package bTree.LeetCode;

import java.util.Arrays;
import java.util.Collections;
import java.util.Stack;

public class 删除字符串中的所有相邻重复项 {
    public String removeDuplicates(String s) {
        Stack<Character>stack=new Stack<>();
        stack.push(s.charAt(0));
        for(int i=1;i<s.length();i++){
            if(!stack.isEmpty()&&s.charAt(i)==stack.peek()){
                stack.pop();
            }else {
                stack.push(s.charAt(i));
            }
        }
        StringBuilder sb=new StringBuilder();
        while (!stack.isEmpty()){
            sb.append(stack.pop());
        }
        return sb.reverse().toString();
    }
}